package org.oos.lists;

import java.util.AbstractList;
import java.util.List;

import org.oos.OOS4Java;
import org.oos.atom.entries.SiteEntry;
import org.oos.model.Site;
import org.oos.util.Cache;

public class SiteList extends AbstractList<Site> {

	private OOS4Java oos4Java;
	private List<SiteEntry> list;
	private Cache<SiteEntry, Site> cache = new Cache<SiteEntry, Site>();

	public SiteList(OOS4Java oos4Java, List<SiteEntry> list) {
		this.oos4Java = oos4Java;
		this.list = list;
	}

	@Override
	public Site get(int location) {
		SiteEntry entry = list.get(location);
		Site result;
		if (cache.containsKey(entry)) {
			result = cache.get(entry);
		} else {
			result = new Site(oos4Java, list.get(location));
			cache.put(entry, result);
		}
		return result;
	}

	@Override
	public int size() {
		return list.size();
	}
}
